**************************************************************
*HURRICANES AND GAS GOUGING - APPENDIX REPORTING AND OUTAGE REGRESSIONS
**************************************************************
frame copy default report_regs_app, replace
frame change report_regs_app
keep if sample_main==1
gsort station_id date

***
*CREATING VARIABLES

*Open
gen open = !missing(retail) | !missing(retail_midgrade) | !missing(retail_premium)

*Recode Outage Data 
gen outage_continuous = 0
replace outage_continuous = 0.05 if outage_level_daymax == 1
replace outage_continuous = 0.15 if outage_level_daymax == 2
replace outage_continuous = 0.25 if outage_level_daymax == 3
replace outage_continuous = 0.35 if outage_level_daymax == 4
replace outage_continuous = 0.50 if outage_level_daymax == 5
replace outage_continuous = 0.65 if outage_level_daymax == 6
replace outage_continuous = 0.80 if outage_level_daymax == 7
replace outage_continuous = 0.95 if outage_level_daymax == 8

*FEMA Disaster Declaration
egen fema = rowmax(fema_disaster fema_indiv_hh_disaster)	

*Creating day 0 event-study indicators

*Hurricane landfalls day 0
gsort station_id date
gen hur_landfall_d0=0 
	replace hur_landfall_d0=1 if BONCHAR_landfall==1 & date==`=td(12aug2004)'
	replace hur_landfall_d0=1 if FRANCES_landfall==1 & date==`=td(06sep2004)'
	replace hur_landfall_d0=1 if IVAN_landfall==1 & date==`=td(16sep2004)'
	replace hur_landfall_d0=1 if JEANNE_landfall==1 & date==`=td(26sep2004)'
	replace hur_landfall_d0=1 if ARLENE_landfall==1 & date==`=td(11jun2005)'
	replace hur_landfall_d0=1 if DENNIS_landfall==1 & date==`=td(10jul2005)'
	replace hur_landfall_d0=1 if KATRINA_FL_landfall==1 & date==`=td(25aug2005)'
	replace hur_landfall_d0=1 if KATRINA_LA_landfall==1 & date==`=td(29aug2005)'
	replace hur_landfall_d0=1 if RITA_landfall==1 & date==`=td(24sep2005)'
	replace hur_landfall_d0=1 if WILMA_landfall==1 & date==`=td(24oct2005)'
	replace hur_landfall_d0=1 if ALBERTO_landfall==1 & date==`=td(13jun2006)'
	replace hur_landfall_d0=1 if HUMBERTO_landfall==1 & date==`=td(13sep2007)'
	replace hur_landfall_d0=1 if GUSTAV_landfall==1 & date==`=td(01sep2008)'
	replace hur_landfall_d0=1 if IKE_landfall==1 & date==`=td(13sep2008)'

*Creating 14-day event windows   
gen event_day=. //Event day variable
	replace event_day=0 if hur_landfall_d0==1
	
*Indicators: 14 Days Prior to Hurricane for Different Samples
forvalues t = 1/14 {
	local n=-1*(`t')
	*Year check
	gen y=f`t'.year
	*Landfall indicator
	gen hur_landfall_dn`t' = 0
		replace hur_landfall_dn`t' = 1 if f`t'.hur_landfall_d0==1 & y==year
	*Event day  
	replace event_day=`n' if hur_landfall_dn`t'==1
	drop y
}
*
*Indicators: 14 Days After Hurricane
forvalues t = 1/14 {
	*Year check
	gen y=l`t'.year
	*Landfall indicator
	gen hur_landfall_d`t' = 0		
		replace hur_landfall_d`t' = 1 if l`t'.hur_landfall_d0==1 & y==year
	*Event day  
	replace event_day=`t' if hur_landfall_d`t'==1
	drop y		
}
*
order hur_landfall_dn14 hur_landfall_dn13 hur_landfall_dn12 hur_landfall_dn11 ///
      hur_landfall_dn10 hur_landfall_dn9 hur_landfall_dn8 hur_landfall_dn7 ///
	  hur_landfall_dn6 hur_landfall_dn5 hur_landfall_dn4 hur_landfall_dn3 ///
	  hur_landfall_dn2 hur_landfall_dn1 hur_landfall_d0 hur_landfall_d1 ///
	  hur_landfall_d2 hur_landfall_d3 hur_landfall_d4 hur_landfall_d5 ///
	  hur_landfall_d6 hur_landfall_d7 hur_landfall_d8 hur_landfall_d9 ///
	  hur_landfall_d10 hur_landfall_d11 hur_landfall_d12 hur_landfall_d13 ///
	  hur_landfall_d14, last

*Event window indicators 
egen window_landfall=rowtotal(hur_landfall_dn14-hur_landfall_d14)  //Event study - Landfall


********************************************************************************
*FIGURE	B.3 - NORMALIZED TRAFFIC LEVELS EVENT STUDY
********************************************************************************
* Standardize (by Station)
egen tr_mean = mean(tr_totvol), by(station_id)
egen tr_z = sd(tr_totvol), by(station_id)
gen tr_totvol_z = (tr_totvol - tr_mean) / tr_z
drop tr_mean tr_z

gen d=. in 1

gen xb_hur1 = . in 1
gen hi_hur1 = . in 1
gen lo_hur1 = . in 1	

reghdfe tr_totvol_z hur_landfall_dn14-hur_landfall_d14 ///
	if inrange(window_landfall, 1, 10), absorb(station_id year month) nocons cluster(county_FIPS)	

replace d=-14 in 1
replace xb_hur1=0 in 1
replace hi_hur1=0 in 1
replace lo_hur1=0 in 1	

forvalues i = 2/14 {
	local j=-1*(`i'-15)
	replace d=-1*`j' in `i'	
	lincom hur_landfall_dn`j'-hur_landfall_dn14
	replace xb_hur1    = r(estimate) in `i'
	replace hi_hur1 = r(estimate) + 1.96*r(se)  in `i'
	replace lo_hur1 = r(estimate) - 1.96*r(se) in `i'

}

forvalues i = 0/14 {
	local j=`i'+15
	replace d=`i' in `j'
	lincom hur_landfall_d`i'-hur_landfall_dn14
	replace xb_hur1 = r(estimate) in `j'
	replace hi_hur1 = r(estimate) + 1.96*r(se)  in `j'
	replace lo_hur1 = r(estimate) - 1.96*r(se) in `j'
}

tw(connected xb_hur1 d, m(O) mfcolor(white) mlcolor(black) msize(medium) lcolor(cranberry) lwidth(medthick) mlwidth(medium)) ///
    (line hi_hur1 d, lpattern(dash) lcolor(erose)) ///
    (line lo_hur1 d, lpattern(dash) lcolor(erose)), ///
    graphr(color(white)) ///
    yscale(noline) ///
    xtit("Days Before/After Hurricane Landfall") ///
    ytit("Change in Traffic (Normalized)") ///
    yline(0, lcolor(cranberry))   ///
    xline(0,lcolor(black) lp(dash)) ///
    legend(off)  
graph export $figs/traffic_no_controls_$outputdate.png, replace width(4000)
drop d-lo_hur1
*
********************************************************************************
*FIGURE	B.4 - POWER OUTAGE EVENT STUDY
********************************************************************************
gen d=. in 1

gen xb_hur1 = . in 1
gen hi_hur1 = . in 1
gen lo_hur1 = . in 1	

reghdfe outage_continuous hur_landfall_dn14-hur_landfall_d14 ///
	if inrange(window_landfall, 1, 10), absorb(station_id year month) nocons cluster(county_FIPS)	

replace d=-14 in 1
replace xb_hur1=0 in 1
replace hi_hur1=0 in 1
replace lo_hur1=0 in 1	

forvalues i = 2/14 {
	local j=-1*(`i'-15)
	replace d=-1*`j' in `i'	
	lincom hur_landfall_dn`j'-hur_landfall_dn14
	replace xb_hur1    = r(estimate) in `i'
	replace hi_hur1 = r(estimate) + 1.96*r(se)  in `i'
	replace lo_hur1 = r(estimate) - 1.96*r(se) in `i'

}

forvalues i = 0/14 {
	local j=`i'+15
	replace d=`i' in `j'
	lincom hur_landfall_d`i'-hur_landfall_dn14
	replace xb_hur1 = r(estimate) in `j'
	replace hi_hur1 = r(estimate) + 1.96*r(se)  in `j'
	replace lo_hur1 = r(estimate) - 1.96*r(se) in `j'
}

tw(connected xb_hur1 d, m(O) mfcolor(white) mlcolor(black) msize(medium) lcolor(cranberry) lwidth(medthick) mlwidth(medium)) ///
    (line hi_hur1 d, lpattern(dash) lcolor(erose)) ///
    (line lo_hur1 d, lpattern(dash) lcolor(erose)), ///
    graphr(color(white)) ///
    yscale(noline) ///
    xtit("Days Before/After Hurricane Landfall") ///
    ytit("Change in Power Outage") ///
    yline(0, lcolor(cranberry))   ///
    xline(0,lcolor(black) lp(dash)) ///
    legend(off)  
graph export $figs/outage_no_controls_$outputdate.png, replace width(4000)
drop d-lo_hur1
frame change default